package com.ruoyi.web.controller.system;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.HgtOperationDo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Questionpaper;
import com.ruoyi.system.service.IQuestionpaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调查问卷Controller
 * 
 * @author ruoyi
 * @date 2023-12-24
 */
@RestController
@RequestMapping("/system/questionpaper")
public class QuestionpaperController extends BaseController
{
    @Autowired
    private IQuestionpaperService questionpaperService;

    /**
     * 查询调查问卷列表
     */
    @PreAuthorize("@ss.hasPermi('system:questionpaper:list')")
    @GetMapping("/list")
    public TableDataInfo list(Questionpaper questionpaper)
    {
        startPage();
        List<Questionpaper> list = questionpaperService.selectQuestionpaperList(questionpaper);
        return getDataTable(list);
    }
    @PostMapping ("tijiao")
    HashMap<Object, Object> tijiao(@RequestBody Questionpaper questionpaper) {
        HashMap<Object, Object> map = new HashMap<>();
        HashMap<Object, Object> aa = new HashMap<>();
        questionpaperService.insertQuestionpaper(questionpaper);
        aa.put("code",0);
        aa.put("msg","提交成功");
        map.put("data",aa);
        return map;
    }
    /**
     * 导出调查问卷列表
     */
    @PreAuthorize("@ss.hasPermi('system:questionpaper:export')")
    @Log(title = "调查问卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Questionpaper questionpaper)
    {
        List<Questionpaper> list = questionpaperService.selectQuestionpaperList(questionpaper);
        ExcelUtil<Questionpaper> util = new ExcelUtil<Questionpaper>(Questionpaper.class);
        util.exportExcel(response, list, "调查问卷数据");
    }

    /**
     * 获取调查问卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:questionpaper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(questionpaperService.selectQuestionpaperById(id));
    }

    /**
     * 新增调查问卷
     */
    @PreAuthorize("@ss.hasPermi('system:questionpaper:add')")
    @Log(title = "调查问卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Questionpaper questionpaper)
    {
        return toAjax(questionpaperService.insertQuestionpaper(questionpaper));
    }

    /**
     * 修改调查问卷
     */
    @PreAuthorize("@ss.hasPermi('system:questionpaper:edit')")
    @Log(title = "调查问卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Questionpaper questionpaper)
    {
        return toAjax(questionpaperService.updateQuestionpaper(questionpaper));
    }

    /**
     * 删除调查问卷
     */
    @PreAuthorize("@ss.hasPermi('system:questionpaper:remove')")
    @Log(title = "调查问卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(questionpaperService.deleteQuestionpaperByIds(ids));
    }


    @GetMapping("/shenhe/{ids}")
    public AjaxResult shenhe(@PathVariable Long ids)
    {
        System.out.println(">>>>>>>>>>>>>>..."+ids);
        return toAjax(questionpaperService.shenheQuestionpaperById(ids));
    }

}
